home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / The World of Computer Software.iso / muzsrc1.zip / SYMCLASS.CPP < prev   
C/C++ Source or Header  |  1992-07-21  |  16KB  |  545 lines

  1. // **********************************************
  2. // File: SYMCLASS.CPP
  3. // Symbols classes library
  4.  
  5. #include "muzika.h"
  6. #include "dialog.h"
  7. #include "objects.h"
  8. #include <values.h>
  9. #include <stdio.h>
  10.  
  11. // **********************************************
  12. // Following are the member function definitions for
  13. // the generic SymbolClass class, from which all the symbol
  14. // classes are derived.
  15.  
  16. // **********************************************
  17. // SymbolClass::BitmapName returns the bitmap name
  18. // (without the "B_" prefix) of the symbol in the resource file.
  19.  
  20. int SymbolClass :: BitmapName(LPSTR lpBuffer, int nBufferMax)
  21. {
  22.   // Load the bitmap name from the string table in the resource file
  23.   return LoadString(hInst, symbolID, lpBuffer, nBufferMax);
  24. }
  25.  
  26. // **********************************************
  27. // SymbolClass::DrawSymbol draws the symbol at its place
  28. // on the screen, derived from its ID code. The symbol is drawn
  29. // in normal or reverse video, according to whether it is active or not.
  30.  
  31. void SymbolClass :: DrawSymbol(HDC hDC, HDC hBitmapDC, BOOL active)
  32. {
  33.   HBITMAP hBitmap, hOldBitmap;
  34.   char name[19] = "B_";
  35.  
  36.   // Test if the symbol exists at all
  37.   if (BitmapName(name+2, sizeof(name)-2)) {
  38.     // Load the symbol bitmap from the resource file
  39.     hBitmap = LoadBitmap(hInst, name);
  40.     hOldBitmap = SelectObject(hBitmapDC, hBitmap);
  41.  
  42.     // Display the bitmap in normal or reverse video
  43.     if (active)
  44.       BitBlt(hDC, 2+36*(symbolID%2), 38+24*(symbolID%0x10/2), 32, 20,
  45.         hBitmapDC, 0, 0, NOTSRCCOPY);
  46.     else
  47.       BitBlt(hDC, 2+36*(symbolID%2), 38+24*(symbolID%0x10/2), 32, 20,
  48.         hBitmapDC, 0, 0, SRCCOPY);
  49.     SelectObject(hBitmapDC, hOldBitmap);
  50.     DeleteObject(hBitmap);
  51.   }
  52. }
  53.  
  54. // **********************************************
  55. // The NullSymbol class, derived from SymbolClass,
  56. // is the default for the "empty slot" symbols.
  57. // It does nothing except drawing an empty rectangle
  58. // as its DrawSymbol function.
  59.  
  60. NullSymbol :: NullSymbol()
  61. {
  62.   symbolID = MAXINT;
  63. }
  64.  
  65. void NullSymbol :: DrawSymbol(HDC hDC, int ID)
  66. {
  67.   Rectangle(hDC, 36*(ID%2), 36+24*(ID%0x10/2),
  68.     36*(ID%2+1)+1, 36+24*(ID%0x10/2+1)+1);
  69. }
  70.  
  71. NullSymbol nullSymbol;
  72.  
  73. // **********************************************
  74. // Following are definitions of various symbol classes,
  75. // all derived from the generic SymbolClass.
  76. // For each symbol class there is a constructor,
  77. // putting values in the symbolID and symbolType variables,
  78. // and a CreateObject function, which returns a pointer
  79. // to a newly created MusicalObject corresponding to the symbol.
  80. // Any future extensions of symbols should be added here.
  81.  
  82. class FullNoteSymbol : virtual public SymbolClass {
  83.   public:
  84.     FullNoteSymbol() {symbolID = 16; symbolType = POINTOBJECT;}
  85.     virtual MusicalObject *CreateObject(int, int X, int Y);
  86. } FullNoteSymbol;
  87.  
  88. MusicalObject *FullNoteSymbol :: CreateObject(int, int X, int Y)
  89. {
  90.   return new Note(X, Y, FULLDURATION);
  91. }
  92.  
  93. class FullPauseSymbol : virtual public SymbolClass {
  94.   public:
  95.     FullPauseSymbol() {symbolID = 17; symbolType = POINTOBJECT;}
  96.     virtual MusicalObject *CreateObject(int, int X, int);
  97. } FullPauseSymbol;
  98.  
  99. MusicalObject *FullPauseSymbol :: CreateObject(int, int X, int)
  100. {
  101.   return new Pause(X, FULLDURATION);
  102. }
  103.  
  104. class HalfNoteSymbol : virtual public SymbolClass {
  105.   public:
  106.     HalfNoteSymbol() {symbolID = 18; symbolType = POINTOBJECT;}
  107.     virtual MusicalObject *CreateObject(int, int X, int Y);
  108. } HalfNoteSymbol;
  109.  
  110. MusicalObject *HalfNoteSymbol :: CreateObject(int, int X, int Y)
  111. {
  112.   return new Note(X, Y, HALFDURATION);
  113. }
  114.  
  115. class HalfPauseSymbol : virtual public SymbolClass {
  116.   public:
  117.     HalfPauseSymbol() {symbolID = 19; symbolType = POINTOBJECT;}
  118.     virtual MusicalObject *CreateObject(int, int X, int);
  119. } HalfPauseSymbol;
  120.  
  121. MusicalObject *HalfPauseSymbol :: CreateObject(int, int X, int)
  122. {
  123.   return new Pause(X, HALFDURATION);
  124. }
  125.  
  126. class QuarterNoteSymbol : virtual public SymbolClass {
  127.   public:
  128.     QuarterNoteSymbol() {symbolID = 20; symbolType = POINTOBJECT;}
  129.     virtual MusicalObject *CreateObject(int, int X, int Y);
  130. } QuarterNoteSymbol;
  131.  
  132. MusicalObject *QuarterNoteSymbol :: CreateObject(int, int X, int Y)
  133. {
  134.   return new Note(X, Y, QUARTERDURATION);
  135. }
  136.  
  137. class QuarterPauseSymbol : virtual public SymbolClass {
  138.   public:
  139.     QuarterPauseSymbol() {symbolID = 21; symbolType = POINTOBJECT;}
  140.     virtual MusicalObject *CreateObject(int, int X, int);
  141. } QuarterPauseSymbol;
  142.  
  143. MusicalObject *QuarterPauseSymbol :: CreateObject(int, int X, int)
  144. {
  145.   return new Pause(X, QUARTERDURATION);
  146. }
  147.  
  148. class EighthNoteSymbol : virtual public SymbolClass {
  149.   public:
  150.     EighthNoteSymbol() {symbolID = 22; symbolType = POINTOBJECT;}
  151.     virtual MusicalObject *CreateObject(int, int X, int Y);
  152. } EighthNoteSymbol;
  153.  
  154. MusicalObject *EighthNoteSymbol :: CreateObject(int, int X, int Y)
  155. {
  156.   return new Note(X, Y, EIGHTHDURATION);
  157. }
  158.  
  159. class EighthPauseSymbol : virtual public SymbolClass {
  160.   public:
  161.     EighthPauseSymbol() {symbolID = 23; symbolType = POINTOBJECT;}
  162.     virtual MusicalObject *CreateObject(int, int X, int);
  163. } EighthPauseSymbol;
  164.  
  165. MusicalObject *EighthPauseSymbol :: CreateObject(int, int X, int)
  166. {
  167.   return new Pause(X, EIGHTHDURATION);
  168. }
  169.  
  170. class SixteenthNoteSymbol : virtual public SymbolClass {
  171.   public:
  172.     SixteenthNoteSymbol() {symbolID = 24; symbolType = POINTOBJECT;}
  173.     virtual MusicalObject *CreateObject(int, int X, int Y);
  174. } SixteenthNoteSymbol;
  175.  
  176. MusicalObject *SixteenthNoteSymbol :: CreateObject(int, int X, int Y)
  177. {
  178.   return new Note(X, Y, SIXTEENTHDURATION);
  179. }
  180.  
  181. class SixteenthPauseSymbol : virtual public SymbolClass {
  182.   public:
  183.     SixteenthPauseSymbol() {symbolID = 25; symbolType = POINTOBJECT;}
  184.     virtual MusicalObject *CreateObject(int, int X, int);
  185. } SixteenthPauseSymbol;
  186.  
  187. MusicalObject *SixteenthPauseSymbol :: CreateObject(int, int X, int)
  188. {
  189.   return new Pause(X, SIXTEENTHDURATION);
  190. }
  191.  
  192. class KeySolSymbol : virtual public SymbolClass {
  193.   public:
  194.     KeySolSymbol() {symbolID = 32; symbolType = POINTOBJECT;}
  195.     MusicalObject *CreateObject(int, int X, int);
  196. } KeySolSymbol;
  197.  
  198. MusicalObject *KeySolSymbol :: CreateObject(int, int X, int)
  199. {
  200.   return new Key(X, KEYSOL);
  201. }
  202.  
  203. class KeyFaSymbol : virtual public SymbolClass {
  204.   public:
  205.     KeyFaSymbol() {symbolID = 33; symbolType = POINTOBJECT;}
  206.     MusicalObject *CreateObject(int, int X, int);
  207. } KeyFaSymbol;
  208.  
  209. MusicalObject *KeyFaSymbol :: CreateObject(int, int X, int)
  210. {
  211.   return new Key(X, KEYFA);
  212. }
  213.  
  214. class BeatCSymbol : virtual public SymbolClass {
  215.   public:
  216.     BeatCSymbol() {symbolID = 48; symbolType = POINTOBJECT;}
  217.     MusicalObject *CreateObject(int, int X, int);
  218. } BeatCSymbol;
  219.  
  220. MusicalObject *BeatCSymbol :: CreateObject(int, int X, int)
  221. {
  222.   return new Beat(X, BEATC);
  223. }
  224.  
  225. class BeatCBarSymbol : virtual public SymbolClass {
  226.   public:
  227.     BeatCBarSymbol() {symbolID = 49; symbolType = POINTOBJECT;}
  228.     MusicalObject *CreateObject(int, int X, int);
  229. } BeatCBarSymbol;
  230.  
  231. MusicalObject *BeatCBarSymbol :: CreateObject(int, int X, int)
  232. {
  233.   return new Beat(X, BEATCBAR);
  234. }
  235.  
  236. class Beat28Symbol : virtual public SymbolClass {
  237.   public:
  238.     Beat28Symbol() {symbolID = 50; symbolType = POINTOBJECT;}
  239.     MusicalObject *CreateObject(int, int X, int);
  240. } Beat28Symbol;
  241.  
  242. MusicalObject *Beat28Symbol :: CreateObject(int, int X, int)
  243. {
  244.   return new Beat(X, BEAT28);
  245. }
  246.  
  247. class Beat24Symbol : virtual public SymbolClass {
  248.   public:
  249.     Beat24Symbol() {symbolID = 51; symbolType = POINTOBJECT;}
  250.     MusicalObject *CreateObject(int, int X, int);
  251. } Beat24Symbol;
  252.  
  253. MusicalObject *Beat24Symbol :: CreateObject(int, int X, int)
  254. {
  255.   return new Beat(X, BEAT24);
  256. }
  257.  
  258. class Beat38Symbol : virtual public SymbolClass {
  259.   public:
  260.     Beat38Symbol() {symbolID = 52; symbolType = POINTOBJECT;}
  261.     MusicalObject *CreateObject(int, int X, int);
  262. } Beat38Symbol;
  263.  
  264. MusicalObject *Beat38Symbol :: CreateObject(int, int X, int)
  265. {
  266.   return new Beat(X, BEAT38);
  267. }
  268.  
  269. class Beat34Symbol : virtual public SymbolClass {
  270.   public:
  271.     Beat34Symbol() {symbolID = 53; symbolType = POINTOBJECT;}
  272.     MusicalObject *CreateObject(int, int X, int);
  273. } Beat34Symbol;
  274.  
  275. MusicalObject *Beat34Symbol :: CreateObject(int, int X, int)
  276. {
  277.   return new Beat(X, BEAT34);
  278. }
  279.  
  280. class Beat48Symbol : virtual public SymbolClass {
  281.   public:
  282.     Beat48Symbol() {symbolID = 54; symbolType = POINTOBJECT;}
  283.     MusicalObject *CreateObject(int, int X, int);
  284. } Beat48Symbol;
  285.  
  286. MusicalObject *Beat48Symbol :: CreateObject(int, int X, int)
  287. {
  288.   return new Beat(X, BEAT48);
  289. }
  290.  
  291. class Beat44Symbol : virtual public SymbolClass {
  292.   public:
  293.     Beat44Symbol() {symbolID = 55; symbolType = POINTOBJECT;}
  294.     MusicalObject *CreateObject(int, int X, int);
  295. } Beat44Symbol;
  296.  
  297. MusicalObject *Beat44Symbol :: CreateObject(int, int X, int)
  298. {
  299.   return new Beat(X, BEAT44);
  300. }
  301.  
  302. class Beat68Symbol : virtual public SymbolClass {
  303.   public:
  304.     Beat68Symbol() {symbolID = 56; symbolType = POINTOBJECT;}
  305.     MusicalObject *CreateObject(int, int X, int);
  306. } Beat68Symbol;
  307.  
  308. MusicalObject *Beat68Symbol :: CreateObject(int, int X, int)
  309. {
  310.   return new Beat(X, BEAT68);
  311. }
  312.  
  313. class BarSymbol : virtual public SymbolClass {
  314.   public:
  315.     BarSymbol() {symbolID = 64; symbolType = POINTOBJECT;}
  316.     MusicalObject *CreateObject(int, int X, int);
  317. } BarSymbol;
  318.  
  319. MusicalObject *BarSymbol :: CreateObject(int, int X, int)
  320. {
  321.   return new Bar(X, BAR);
  322. }
  323.  
  324. class DoubleBarSymbol : virtual public SymbolClass {
  325.   public:
  326.     DoubleBarSymbol() {symbolID = 65; symbolType = POINTOBJECT;}
  327.     MusicalObject *CreateObject(int, int X, int);
  328. } DoubleBarSymbol;
  329.  
  330. MusicalObject *DoubleBarSymbol :: CreateObject(int, int X, int)
  331. {
  332.   return new Bar(X, DOUBLEBAR);
  333. }
  334.  
  335. class StartBarSymbol : virtual public SymbolClass {
  336.   public:
  337.     StartBarSymbol() {symbolID = 66; symbolType = POINTOBJECT;}
  338.     MusicalObject *CreateObject(int, int X, int);
  339. } StartBarSymbol;
  340.  
  341. MusicalObject *StartBarSymbol :: CreateObject(int, int X, int)
  342. {
  343.   return new Bar(X, STARTBAR);
  344. }
  345.  
  346. class EndBarSymbol : virtual public SymbolClass {
  347.   public:
  348.     EndBarSymbol() {symbolID = 67; symbolType = POINTOBJECT;}
  349.     MusicalObject *CreateObject(int, int X, int);
  350. } EndBarSymbol;
  351.  
  352. MusicalObject *EndBarSymbol :: CreateObject(int, int X, int)
  353. {
  354.   return new Bar(X, ENDBAR);
  355. }
  356.  
  357. class ForteSymbol : virtual public SymbolClass {
  358.   public:
  359.     ForteSymbol() {symbolID = 80; symbolType = POINTOBJECT;}
  360.     virtual MusicalObject *CreateObject(int, int X, int);
  361. } ForteSymbol;
  362.  
  363. MusicalObject *ForteSymbol :: CreateObject(int, int X, int)
  364. {
  365.   return new Loudness(X, FORTE);
  366. }
  367.  
  368. class FortissimoSymbol : virtual public SymbolClass {
  369.   public:
  370.     FortissimoSymbol() {symbolID = 81; symbolType = POINTOBJECT;}
  371.     virtual MusicalObject *CreateObject(int, int X, int);
  372. } FortissimoSymbol;
  373.  
  374. MusicalObject *FortissimoSymbol :: CreateObject(int, int X, int)
  375. {
  376.   return new Loudness(X, FORTISSIMO);
  377. }
  378.  
  379. class PianoSymbol : virtual public SymbolClass {
  380.   public:
  381.     PianoSymbol() {symbolID = 82; symbolType = POINTOBJECT;}
  382.     virtual MusicalObject *CreateObject(int, int X, int);
  383. } PianoSymbol;
  384.  
  385. MusicalObject *PianoSymbol :: CreateObject(int, int X, int)
  386. {
  387.   return new Loudness(X, PIANO);
  388. }
  389.  
  390. class PianissimoSymbol : virtual public SymbolClass {
  391.   public:
  392.     PianissimoSymbol() {symbolID = 83; symbolType = POINTOBJECT;}
  393.     virtual MusicalObject *CreateObject(int, int X, int);
  394. } PianissimoSymbol;
  395.  
  396. MusicalObject *PianissimoSymbol :: CreateObject(int, int X, int)
  397. {
  398.   return new Loudness(X, PIANISSIMO);
  399. }
  400.  
  401. class CrescendoSymbol : virtual public SymbolClass {
  402.   public:
  403.     CrescendoSymbol() {symbolID = 84; symbolType = CONTINUOUSOBJECT;}
  404.     MusicalObject *CreateObject(int, int Xleft, int Xright);
  405. } CrescendoSymbol;
  406.  
  407. MusicalObject *CrescendoSymbol :: CreateObject(int, int Xleft, int Xright)
  408. {
  409.   return new Crescendo(Xleft, Xright, CRESCENDO);
  410. }
  411.  
  412. class DiminuendoSymbol : virtual public SymbolClass {
  413.   public:
  414.     DiminuendoSymbol() {symbolID = 85; symbolType = CONTINUOUSOBJECT;}
  415.     MusicalObject *CreateObject(int, int Xleft, int Xright);
  416. } DiminuendoSymbol;
  417.  
  418. MusicalObject *DiminuendoSymbol :: CreateObject(int, int Xleft, int Xright)
  419. {
  420.   return new Crescendo(Xleft, Xright, DIMINUENDO);
  421. }
  422.  
  423. class TextSymbol : virtual public SymbolClass {
  424.   public:
  425.     TextSymbol() {symbolID = 96; symbolType = POINTOBJECT;}
  426.     MusicalObject *CreateObject(int staff, int X, int Y);
  427. } TextSymbol;
  428.  
  429. char _text[MAXTEXT+1];
  430.  
  431. // **********************************************
  432. // DialogText is the function of the dialog box
  433. // that appears when a Text object is inserted.
  434.  
  435. BOOL FAR PASCAL _export DialogText(HWND hDlg, unsigned message, WORD wParam, LONG)
  436. {
  437.   switch (message) {
  438.     case WM_INITDIALOG:
  439.       SendDlgItemMessage(hDlg, ID_TEXT, EM_LIMITTEXT, MAXTEXT, 0);
  440.       return TRUE;
  441.  
  442.     case WM_COMMAND:
  443.       if (wParam == IDOK) {
  444.         GetDlgItemText(hDlg, ID_TEXT, _text, MAXTEXT);
  445.         EndDialog(hDlg, 0);
  446.       }
  447.       return TRUE;
  448.   }
  449.  
  450.   return FALSE;
  451. }
  452.  
  453. MusicalObject *TextSymbol :: CreateObject(int, int X, int Y)
  454. {
  455.   FARPROC lpDialog = MakeProcInstance((FARPROC) DialogText, hInst);
  456.   DialogBox(hInst, "D_TEXT", hMainWnd, lpDialog);
  457.   FreeProcInstance(lpDialog);
  458.   return new Text(X, Y, _text);
  459. }
  460.  
  461. // **********************************************
  462. // The block operation symbols are in no way different
  463. // from any other symbols; their constructors and
  464. // CreateObject functions are similar to those of any
  465. // of the symbols above. However, the CreateObject function
  466. // in these symbols returns a NULL value, indicating
  467. // that no object has been created as a result of the operation.
  468.  
  469. class MarkBlockSymbol : virtual public SymbolClass {
  470.   public:
  471.     MarkBlockSymbol() {symbolID = 112; symbolType = CONTINUOUSOBJECT;}
  472.     MusicalObject *CreateObject(int staff, int Xleft, int Xright);
  473. } MarkBlockSymbol;
  474.  
  475. MusicalObject *MarkBlockSymbol :: CreateObject(int staff, int Xleft, int Xright)
  476. {
  477.   MarkBlock(staff, Xleft, staff, Xright);
  478.   return NULL;
  479. }
  480.  
  481. class CutBlockSymbol : virtual public SymbolClass {
  482.   public:
  483.     CutBlockSymbol() {symbolID = 113; symbolType = POINTOBJECT;}
  484.     MusicalObject *CreateObject(int, int, int);
  485. } CutBlockSymbol;
  486.  
  487. MusicalObject *CutBlockSymbol :: CreateObject(int, int, int)
  488. {
  489.   CutBlock();
  490.   return NULL;
  491. }
  492.  
  493. class CopyBlockSymbol : virtual public SymbolClass {
  494.   public:
  495.     CopyBlockSymbol() {symbolID = 114; symbolType = POINTOBJECT;}
  496.     MusicalObject *CreateObject(int, int, int);
  497. } CopyBlockSymbol;
  498.  
  499. MusicalObject *CopyBlockSymbol :: CreateObject(int, int, int)
  500. {
  501.   CopyBlock();
  502.   return NULL;
  503. }
  504.  
  505. class PasteBlockSymbol : virtual public SymbolClass {
  506.   public:
  507.     PasteBlockSymbol() {symbolID = 115; symbolType = POINTOBJECT;}
  508.     MusicalObject *CreateObject(int staff, int X, int);
  509. } PasteBlockSymbol;
  510.  
  511. MusicalObject *PasteBlockSymbol :: CreateObject(int staff, int X, int)
  512. {
  513.   Part &p = *((Part *) &melody.part[displayedPart]);
  514.   PasteBlock(staff/p.multiplicity()*p.multiplicity(), X);
  515.   return NULL;
  516. }
  517.  
  518. // **********************************************
  519. // The symbolArray is a global array of symbol classes
  520. // in which a symbol with a given ID is searched.
  521. // The list is sorted in the order of increasing ID,
  522. // and ends with a NullSymbol (with the ID of MAXINT).
  523.  
  524. SymbolClass *symbolArray[] = {
  525.   &FullNoteSymbol, &FullPauseSymbol,
  526.   &HalfNoteSymbol, &HalfPauseSymbol,
  527.   &QuarterNoteSymbol, &QuarterPauseSymbol,
  528.   &EighthNoteSymbol, &EighthPauseSymbol,
  529.   &SixteenthNoteSymbol, &SixteenthPauseSymbol,
  530.   &KeySolSymbol, &KeyFaSymbol,
  531.   &BeatCSymbol, &BeatCBarSymbol,
  532.   &Beat28Symbol, &Beat24Symbol,
  533.   &Beat38Symbol, &Beat34Symbol,
  534.   &Beat48Symbol, &Beat44Symbol,
  535.   &Beat68Symbol,
  536.   &BarSymbol, &DoubleBarSymbol,
  537.   &StartBarSymbol, &EndBarSymbol,
  538.   &ForteSymbol, &FortissimoSymbol,
  539.   &PianoSymbol, &PianissimoSymbol,
  540.   &CrescendoSymbol, &DiminuendoSymbol,
  541.   &TextSymbol,
  542.   &MarkBlockSymbol, &CutBlockSymbol,
  543.   &CopyBlockSymbol, &PasteBlockSymbol,
  544.   &nullSymbol};
  545.